
//524.通过删除字母匹配到字典里最长单词
class Solution {
public:
    string findLongestWord(string s, vector<string>& dictionary) {
        //将数组中的之字符串与s一一对比
        int n=s.size();
        string ret="";
        for(auto str:dictionary)
        {
            int m=str.size();
            int i=0,j=0;
            while(i<n&&j<m)
            {
                if(s[i]==str[j]) j++;
                i++;
            }
            if(j==m)
            {
                if(str.size()>ret.size()) ret=str;
                else if(str.size()==ret.size()&&str<ret) ret=str;
            }
        }
        return ret;
    }
};